package opera;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class AddOperation implements IOpreation{
    @Override
    public void work(BookList bookList) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("添加图书！");

        System.out.println("请输入书名：");
        String name = scanner.nextLine();

        System.out.println("请输入作者：");
        String author = scanner.nextLine();

        System.out.println("请输入类型：");
        String type = scanner.nextLine();

        System.out.println("请输入价格：");
        int price = scanner.nextInt();


        Book book = new Book(name,author,price,type);

        int a = bookList.getUsedSize();
        for (int i = 0; i < a; i++) {
            Book tmp = bookList.getBooks(i);
            if (tmp.getName().equals(name) ){
                System.out.println("已经有此类书本，无需再次添加。");
                return;
            }
        }

        bookList.setBooks(book);
        bookList.setUsedSize(a+1);
    }
}
